package com.softoa.contorller;

import com.softoa.pojo.Historynews;
import com.softoa.pojo.News;
import com.softoa.pojo.Session;
import com.softoa.pojo.SessionInfo;
import com.softoa.service.ISessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/session")

public class SessionController {
    /**
     * 写了
     */
    @Autowired
    ISessionService iSessionService;
    @RequestMapping("sessioninsert")
    public int sessionInsert(Session session){
        return iSessionService.sessionInsert(session);
    };
    @RequestMapping("sessionupdate")
    public int sessionUpdate(Session session){
        return iSessionService.sessionUpdate(session);
    };
    @RequestMapping("sessionlist")
    public java.util.List<Session> sessionSelectList(String userId){
        return iSessionService.sessionSelectList(userId);
    };
    @RequestMapping("sessionone")
    public Session sessionSelectOne(int sessionId){
        return iSessionService.sessionSelectOne(sessionId);
    };
    @RequestMapping("sessionnews")
    public java.util.List<News> sessionSelectNews(News rule){
        return iSessionService.sessionSelectNews(rule);
    };
    @RequestMapping("sessioninsertnews")
    public int sessionInsertNews(News news){
        return iSessionService.sessionInsertNews(news);
    };

    @RequestMapping("sessionshow")
    public java.util.List<SessionInfo> sessionShow(String userId){
        return iSessionService.sessionShow(Integer.parseInt(userId));

    };
    @RequestMapping("historyshow")
    public java.util.List<Historynews> historyShow(Historynews historynews){
        return iSessionService.historyShow(historynews);
    };
    @RequestMapping("if")
    public boolean ifcerated(Session session){
        String[] two=session.getBothSidesId().split("-");
        String userid=two[1];
        String baseid=two[0];
        java.util.List<Session> list=this.sessionSelectList(userid);
        if(list.size()!=0){
            for (Session s:list){
                String str=s.getBothSidesId();
                if(str.indexOf(baseid)>=0){return false;}
            }
            return true;
        }else {return true;}
    };
}
